
package com.widget;

import com.bluesmart.mia.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;

public class BottleView extends ImageView{
	Context mContext;
	
	Paint mPaint;
    Bitmap userBmp;
    Matrix matrix;

    public BottleView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        
        mPaint=new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
        mPaint.setDither(true); 
        
        userBmp = BitmapFactory.decodeResource(getResources(), R.drawable.bottom_rotato);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(mTotalAngle != mAngle)
        {
        	if(mAngle < mTotalAngle) mAngle++;
			else if(mAngle > mTotalAngle) mAngle--;
        	
        	Log.i("--------------", "" + mAngle);
        	postInvalidate();
        }
        
//        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bottom_rotato);  
//        canvas.drawBitmap(bitmap,0, 0, p);
        
        matrix=new Matrix();
  /*      float xScale=75f/userBmp.getWidth();
        float yScale=75f/userBmp.getHeight();
         
        if(userBmp.getHeight()<userBmp.getWidth())
        {
            matrix.postScale(xScale, yScale);
        }
        else
        {
            matrix.postScale(xScale, xScale);
        }   
        matrix.postScale(1.75f, 1.75f);*/
//        matrix.postTranslate(50, 4);
        matrix.postRotate(45f, getWidth()/2, getHeight()/2);
        matrix.postTranslate(getWidth(), getHeight());
        
        canvas.drawBitmap(userBmp, matrix, mPaint);
        matrix=null;
    }
    
    int mAngle,mTotalAngle;
    public void startRotato(final int angle)
    {
    	mTotalAngle = angle;
    	invalidate();
    }
}
